package kr.co.boogui.actions.admin.news;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.boogui.actions.ActionHandler;
import kr.co.boogui.dao.NewsDAO;
import kr.co.boogui.service.AdminService;
import kr.co.boogui.service.NewsUpdateService;

public class UpdateNewsAction implements ActionHandler {
	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		
		String viewPage = "f|/WEB-INF/jsp/admin/admin.jsp";
		String method = req.getMethod();
		int newsno = Integer.parseInt(req.getParameter("newsno"));
		if (method.equalsIgnoreCase("get")){
			viewPage = AdminService.adminChk(req, "news_update");
			req.setAttribute("newsupdate",NewsDAO.viewBoard(newsno));
			
		} else if (method.equalsIgnoreCase("post")) {		
			try {
				req.setAttribute("action" , "news_update.jsp");
				req.setAttribute("regi", "y");
				
				
				if (NewsUpdateService.newsRegistry(req)){
					req.setAttribute("isregi", "success");
				} else {
					req.setAttribute("isregi", "fail");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
				
		}		
		return viewPage;
	}
}
